package com.example.springboottools.utils;

import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;

import java.awt.image.BufferedImage;
import java.io.File;
import java.net.URL;
import javax.imageio.ImageIO;
import java.io.IOException;
import java.util.Arrays;

public class ImageValidator {

    /**
     * Checks if the image at the given URL can be opened and read.
     *
     * @param imageUrl The URL of the image to check.
     * @return true if the image can be accessed and read, false otherwise.
     */
    public static boolean isImageAccessible(String imageUrl) {
        try {
           // URL url = new URL(imageUrl);
            // Attempt to read the image from the URL
           // ImageIO.read(url.openStream());
            BufferedImage read = ImageIO.read(new File(imageUrl));
            int height = read.getHeight();
            int width = read.getWidth();
            return true;
        } catch (Exception e) {
            // An exception occurred while trying to access the image
            return false;
        }
    }

    public static void main(String[] args) {
       // String testImageUrl = "C:\\Users\\SH102909\\Downloads\\cn7700983228EA_1_xnl.jpg";
//        String testImageUrl = "C:\\Users\\SH102909\\Downloads\\737c8551ef6041038b2aac9678529b52.jpg";
//        if (isImageAccessible(testImageUrl)) {
//            System.out.println("The image is accessible.");
//
//        } else {
//            System.out.println("The image cannot be accessed.");
//        }
        String trim = StringUtils.trim("MC\\u0002ys128");
        String s = StringEscapeUtils.escapeHtml4("MC\\\\u0002ys128");
        System.out.println(s);
    }
}

